import {
  getContractList,
  addContract,
  getLockModel,
  getManageMsg,
  getShipmentData,
  editDiscount,
  getLockModelListByProId
} from "@/api/contract";

function getDetail() {
  let detail = {};
  try {
    detail = JSON.parse(sessionStorage.getItem("contractDetail"));
  } catch (error) {
    return undefined;
  }
  return detail;
}

const state = {
  docsDetail: getDetail() || {}
};
const actions = {
  getContractList({}, payload) {
    return new Promise((resolve, reject) => {
      getContractList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  addContract({}, payload) {
    return new Promise((resolve, reject) => {
      addContract(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getLockModel({}, payload) {
    return new Promise((resolve, reject) => {
      getLockModel(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getManageMsg({}, payload) {
    return new Promise((resolve, reject) => {
      getManageMsg(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getShipmentData({}, payload) {
    return new Promise((resolve, reject) => {
      getShipmentData(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  editDiscount({}, payload) {
    return new Promise((resolve, reject) => {
      editDiscount(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getLockModelListByProId({}, payload) {
    return new Promise((resolve, reject) => {
      getLockModelListByProId(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
};
const mutations = {
  setDocsDetail(state, payload) {
    sessionStorage.setItem("contractDetail", JSON.stringify(payload));
    state.docsDetail = payload;
  },
  resetDocsDetail(state, payload) {
    sessionStorage.removeItem("contractDetail");
    state.docsDetail = {};
  }
};
const getters = {};
export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
};
